home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / include / arpa / nameser.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-07  |  6.4 KB  |  216 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)nameser.h    5.17 (Berkeley) 11/17/87
  7.  */
  8.  
  9. #ifndef _NAMESER_H
  10. #define _NAMESER_H
  11.  
  12. #include <cfuncproto.h>
  13. #include <machparam.h>
  14.  
  15. /*
  16.  * Define constants based on rfc883
  17.  */
  18. #define PACKETSZ    512        /* maximum packet size */
  19. #define MAXDNAME    256        /* maximum domain name */
  20. #define MAXCDNAME    255        /* maximum compressed domain name */
  21. #define MAXLABEL    63        /* maximum length of domain label */
  22.     /* Number of bytes of fixed size data in query structure */
  23. #define QFIXEDSZ    4
  24.     /* number of bytes of fixed size data in resource record */
  25. #define RRFIXEDSZ    10
  26.  
  27. /*
  28.  * Internet nameserver port number
  29.  */
  30. #define NAMESERVER_PORT    53
  31.  
  32. /*
  33.  * Currently defined opcodes
  34.  */
  35. #define QUERY        0x0        /* standard query */
  36. #define IQUERY        0x1        /* inverse query */
  37. #define STATUS        0x2        /* nameserver status query */
  38. /*#define xxx        0x3        /* 0x3 reserved */
  39.     /* non standard */
  40. #define UPDATEA        0x9        /* add resource record */
  41. #define UPDATED        0xa        /* delete a specific resource record */
  42. #define UPDATEDA    0xb        /* delete all nemed resource record */
  43. #define UPDATEM        0xc        /* modify a specific resource record */
  44. #define UPDATEMA    0xd        /* modify all named resource record */
  45.  
  46. #define ZONEINIT    0xe        /* initial zone transfer */
  47. #define ZONEREF        0xf        /* incremental zone referesh */
  48.  
  49. /*
  50.  * Currently defined response codes
  51.  */
  52. #define NOERROR        0        /* no error */
  53. #define FORMERR        1        /* format error */
  54. #define SERVFAIL    2        /* server failure */
  55. #define NXDOMAIN    3        /* non existent domain */
  56. #define NOTIMP        4        /* not implemented */
  57. #define REFUSED        5        /* query refused */
  58.     /* non standard */
  59. #define NOCHANGE    0xf        /* update failed to change db */
  60.  
  61. /*
  62.  * Type values for resources and queries
  63.  */
  64. #define T_A        1        /* host address */
  65. #define T_NS        2        /* authoritative server */
  66. #define T_MD        3        /* mail destination */
  67. #define T_MF        4        /* mail forwarder */
  68. #define T_CNAME        5        /* connonical name */
  69. #define T_SOA        6        /* start of authority zone */
  70. #define T_MB        7        /* mailbox domain name */
  71. #define T_MG        8        /* mail group member */
  72. #define T_MR        9        /* mail rename name */
  73. #define T_NULL        10        /* null resource record */
  74. #define T_WKS        11        /* well known service */
  75. #define T_PTR        12        /* domain name pointer */
  76. #define T_HINFO        13        /* host information */
  77. #define T_MINFO        14        /* mailbox information */
  78. #define T_MX        15        /* mail routing information */
  79.     /* non standard */
  80. #define T_UINFO        100        /* user (finger) information */
  81. #define T_UID        101        /* user ID */
  82. #define T_GID        102        /* group ID */
  83. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  84.     /* Query type values which do not appear in resource records */
  85. #define T_AXFR        252        /* transfer zone of authority */
  86. #define T_MAILB        253        /* transfer mailbox records */
  87. #define T_MAILA        254        /* transfer mail agent records */
  88. #define T_ANY        255        /* wildcard match */
  89.  
  90. /*
  91.  * Values for class field
  92.  */
  93.  
  94. #define C_IN        1        /* the arpa internet */
  95. #define C_CHAOS        3        /* for chaos net at MIT */
  96.     /* Query class values which do not appear in resource records */
  97. #define C_ANY        255        /* wildcard match */
  98.  
  99. /*
  100.  * Status return codes for T_UNSPEC conversion routines
  101.  */
  102. #define CONV_SUCCESS 0
  103. #define CONV_OVERFLOW -1
  104. #define CONV_BADFMT -2
  105. #define CONV_BADCKSUM -3
  106. #define CONV_BADBUFLEN -4
  107.  
  108. /*
  109.  * Structure for query header, the order of the fields is machine and
  110.  * compiler dependent, in our case, the bits within a byte are assignd 
  111.  * least significant first, while the order of transmition is most 
  112.  * significant first.  This requires a somewhat confusing rearrangement.
  113.  */
  114.  
  115. typedef struct {
  116.     u_short    id;        /* query identification number */
  117. #if defined (sun) || defined (sel) || defined (pyr) || defined (is68k) \
  118. || defined (tahoe) || defined (BIT_ZERO_ON_LEFT) || (BYTE_ORDER == BIG_ENDIAN)
  119.     /* Bit zero on left:  Gould and similar architectures */
  120.             /* fields in third byte */
  121.     u_char    qr:1;        /* response flag */
  122.     u_char    opcode:4;    /* purpose of message */
  123.     u_char    aa:1;        /* authoritive answer */
  124.     u_char    tc:1;        /* truncated message */
  125.     u_char    rd:1;        /* recursion desired */
  126.             /* fields in fourth byte */
  127.     u_char    ra:1;        /* recursion available */
  128.     u_char    pr:1;        /* primary server required (non standard) */
  129.     u_char    unused:2;    /* unused bits */
  130.     u_char    rcode:4;    /* response code */
  131. #else
  132. #if defined (vax) || defined(ns32000) || defined (BIT_ZERO_ON_RIGHT) \
  133. || (BYTE_ORDER == LITTLE_ENDIAN)
  134.     /* Bit zero on right:  VAX */
  135.             /* fields in third byte */
  136.     u_char    rd:1;        /* recursion desired */
  137.     u_char    tc:1;        /* truncated message */
  138.     u_char    aa:1;        /* authoritive answer */
  139.     u_char    opcode:4;    /* purpose of message */
  140.     u_char    qr:1;        /* response flag */
  141.             /* fields in fourth byte */
  142.     u_char    rcode:4;    /* response code */
  143.     u_char    unused:2;    /* unused bits */
  144.     u_char    pr:1;        /* primary server required (non standard) */
  145.     u_char    ra:1;        /* recursion available */
  146. #else
  147.     /* you must determine what the correct bit order is for your compiler */
  148.     UNDEFINED_BIT_ORDER;
  149. #endif
  150. #endif
  151.             /* remaining bytes */
  152.     u_short    qdcount;    /* number of question entries */
  153.     u_short    ancount;    /* number of answer entries */
  154.     u_short    nscount;    /* number of authority entries */
  155.     u_short    arcount;    /* number of resource entries */
  156. } HEADER;
  157.  
  158. /*
  159.  * Defines for handling compressed domain names
  160.  */
  161. #define INDIR_MASK    0xc0
  162.  
  163. /*
  164.  * Structure for passing resource records around.
  165.  */
  166. struct rrec {
  167.     short    r_zone;            /* zone number */
  168.     short    r_class;        /* class number */
  169.     short    r_type;            /* type number */
  170.     u_long    r_ttl;            /* time to live */
  171.     int    r_size;            /* size of data area */
  172.     char    *r_data;        /* pointer to data */
  173. };
  174.  
  175. _EXTERN    u_short    _getshort _ARGS_((_CONST u_char *msgp));
  176. _EXTERN    u_long    _getlong _ARGS_((_CONST u_char *msgp));
  177. _EXTERN void putshort _ARGS_ ((u_short s, u_char *msgp));
  178. _EXTERN void putlong _ARGS_ ((u_long s, u_char *msgp));
  179.  
  180. /*
  181.  * Inline versions of get/put short/long.
  182.  * Pointer is advanced; we assume that both arguments
  183.  * are lvalues and will already be in registers.
  184.  * cp MUST be u_char *.
  185.  */
  186. #define GETSHORT(s, cp) { \
  187.     (s) = *(cp)++ << 8; \
  188.     (s) |= *(cp)++; \
  189. }
  190.  
  191. #define GETLONG(l, cp) { \
  192.     (l) = *(cp)++ << 8; \
  193.     (l) |= *(cp)++; (l) <<= 8; \
  194.     (l) |= *(cp)++; (l) <<= 8; \
  195.     (l) |= *(cp)++; \
  196. }
  197.  
  198.  
  199. #define PUTSHORT(s, cp) { \
  200.     *(cp)++ = (s) >> 8; \
  201.     *(cp)++ = (s); \
  202. }
  203.  
  204. /*
  205.  * Warning: PUTLONG destroys its first argument.
  206.  */
  207. #define PUTLONG(l, cp) { \
  208.     (cp)[3] = l; \
  209.     (cp)[2] = (l >>= 8); \
  210.     (cp)[1] = (l >>= 8); \
  211.     (cp)[0] = l >> 8; \
  212.     (cp) += sizeof(u_long); \
  213. }
  214.  
  215. #endif /* _NAMESER_H */
  216.